package com.guang.lock.selfdefinelock;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

/**
 * @Description
 * @Author liguang
 * @Date 2022/10/20/16:05
 */
public class LigLockTest {

    static LigLock lock = new LigLock();
    private final static Logger logger = LoggerFactory.getLogger(LigLockTest.class);
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            lock.lock();
            logger.info("当前是线程{}在执行",Thread.currentThread().getName());
            try {
                TimeUnit.MICROSECONDS.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            lock.unlock();
            logger.info("-------------------------");
        }, "t1");

        Thread t2 = new Thread(() -> {
            lock.lock();
            logger.info("当前是线程{}在执行",Thread.currentThread().getName());
            lock.unlock();
            logger.info("-------------------------");
        }, "t2");

        t1.start();
        TimeUnit.MICROSECONDS.sleep(10);
        t2.start();
    }

}
